<?php
header("Content-type: application/json");
$name = $_POST['username'];
$province = $_POST['province'];
$school = $_POST['school'];
$type = $_POST['type'];

if (empty($name) || empty($province) || empty($school) || empty($type)) {
	echo "信息不全";
	return;
}

$name = str_replace(" ", "", $name);
$ret = $type == 1 ?
shell_exec("python cetaldata/cet4.py '$province' '$school' '$name'") :
shell_exec("python cetaldata/cet6.py '$province' '$school' '$name'");


$ret = json_decode($ret, true);
if ($ret['name'] !== null) {
	$id=$ret['ticket'];
	$ye="20".substr($id,6,2)."年";
	$mo=(substr($id,8, 1) == 1 ? "6" : "12")."月";
	$leiid=substr($id,9,1);
	switch ($leiid) {
		case "1": $lei=$ye.$mo." 英语四级";break;
		case "2": $lei=$ye.$mo." 英语六级";break;
		case "3": $lei=$ye.$mo." 日语四级";break;
		case "4": $lei=$ye.$mo." 日语六级";break;
		case "5": $lei=$ye.$mo." 德语四级";break;
		case "6": $lei=$ye.$mo." 德语六级";break;
		case "7": $lei=$ye.$mo." 俄语四级";break;
		case "8": $lei=$ye.$mo." 俄语六级";break;
		case "9": $lei=$ye.$mo." 法语四级";break;
		default: $lei="";
	}

	$data = [
		"name" => $ret['name'],
		"lei"=>$lei,
		"ticket" => $ret['ticket'],
		"school" => $ret['school'],
		"total" => $ret['total'],
		"writing" => $ret['writing'],
		"listening" => $ret['listening'],
		"reading" => $ret['reading']
	];
	print_r(json_encode($data));
}

?>